<template>
	<view class="relative">
		<view class="margin ">
			<u-gap height="60"></u-gap>
			<!--  -->
			<u-cell-group :border="false">
				<u-cell size="large" title="个人资料" isLink :border="true"
					@click="$pub.go('/pages_my/myMsg/myMsg')"></u-cell>
				<!-- <u-cell size="large" title="账号管理" isLink :border="true"></u-cell> -->
				<u-cell size="large" title="清除缓存" isLink :border="true" :value="currentSize"
					@click="clearStorage"></u-cell>
				<u-cell size="large" title="隐私政策" :border="true" isLink></u-cell>
				<u-cell size="large" :border="false" title="关于我们" isLink>
					<view class="" slot='value'>
						<a href="http://192.168.3.90:8091/app"
							style="text-decoration: none;color: cornflowerblue;width: 100%;">go</a>
					</view>
				</u-cell>
			</u-cell-group>
			<!--  -->
			<!--  -->
		</view>

		<view class="fixed w-full cc " style="bottom: 0;" @click="loginOut">
			<button type="default" class="btn size_16 color_white">
				退出登录
			</button>
			<u-gap></u-gap>
			<!-- <u-gap></u-gap> -->
		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex';

	export default {
		data() {
			return {
				currentSize: "",
			};
		},
		methods: {
			...mapMutations('m_message', ['removeId', 'DELETE_MESSAGE']),
			...mapMutations('m_user', ['removeInfo']),
			async loginOut() {

				/*  */
				let re = await this.$API.authApi.logout();
				uni.clearStorageSync()

				this.$ws.completeClose();
				this.$store.state.isOpenSocket = false;

				uni.reLaunch({
					url: "/pages/logo/logo",
				});

				return;
				uni.removeStorageSync("map");
				this.removeId();
				this.removeInfo();
				// uni.removeStorageSync("orderData");
				/* 删除所有消息 */
				this.DELETE_MESSAGE();
				/* 关闭socket */
				this.$ws.completeClose();
				this.$store.state.isOpenSocket = false;
			},
			// 获取本地缓存大小
			getStorageSize() {
				let that = this;

				// #ifdef APP-PLUS
				plus.cache.calculate(function(size) {
					let sizeCache = parseInt(size);
					if (sizeCache == 0) {
						that.currentSize = "0B";
					} else if (sizeCache < 1024) {
						that.currentSize = sizeCache + "B";
					} else if (sizeCache < 1048576) {
						that.currentSize = (sizeCache / 1024).toFixed(2) + "KB";
					} else if (sizeCache < 1073741824) {
						that.currentSize = (sizeCache / 1048576).toFixed(2) + "MB";
					} else {
						that.currentSize = (sizeCache / 1073741824).toFixed(2) + "GB";
					}
				});
				// #endif
				// #ifdef MP
				let wxSize = uni.getStorageInfoSync().currentSize + 'Kb'
				// #endif


			},
			/*  */
			// 清理缓存
			clearStorage() {
				let that = this;

				// #ifdef APP-PLUS
				let os = plus.os.name;
				if (os == "Android") {
					let main = plus.android.runtimeMainActivity();
					let sdRoot = main.getCacheDir();
					let files = plus.android.invoke(sdRoot, "listFiles");
					let len = files.length;
					console.log(files, len);
					for (let i = 0; i < len; i++) {
						let filePath = "" + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径
						// #ifdef APP-PLUS
						plus.io.resolveLocalFileSystemURL(
							filePath,
							function(entry) {
								if (entry.isDirectory) {
									entry.removeRecursively(
										function(entry) {
											//递归删除其下的所有文件及子目录
											that.files = [];
											uni.showToast({
												title: "清除成功",
												duration: 2000,
											});
											that.getStorageSize(); // 重新计算缓存
										},
										function(e) {
											console.log(e.message);
										}
									);
								} else {
									entry.remove();
								}
							},
							function(e) {
								console.log("文件路径读取失败");
							}
						);
						// #endif


					}
				} else {
					// ios
					// #ifdef APP-PLUS
					plus.cache.clear(function() {
						uni.showToast({
							title: "清除成功",
							duration: 2000,
						});
						that.getStorageSize();
					});
					// #endif
				}
				// #endif


				// #ifdef MP
				wx.removeStorageSync('messageList');
				wx.removeStorageSync('messageSession');
				// #endif
			},
			/*  */
		},
		onLoad() {},

		onShow() {
			/* 设置 */
			uni.setNavigationBarTitle({
				title: "设置",
			});
			/* 计算 */
			this.getStorageSize();
		},
	};
</script>

<style lang="scss" scoped>
	.relative {
		.cc {
			/* 兼容iPhoneX */
			padding-bottom: 0;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
		}

	}

	/* #ifdef MP */
	::v-deep .u-cell__title-text--large {
		font-size: 32rpx !important;
	}

	.u-slot-value {
		font-size: 25rpx !important;
	}

	/* #endif */

	::v-deep .u-cell__title-text--large {
		font-size: 28rpx !important;
	}

	.btn {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 700rpx;
		height: 100rpx;
		background: #7976e9;
		border-radius: 60rpx;
		opacity: 1;
		color: #fff;
	}
</style>